package com.minjiang.blog.config;

import com.github.pagehelper.util.StringUtil;
import org.springframework.web.servlet.LocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

/**
 * 国际化的切换(区域解析器)
 */
public class MyLocaleResolver implements LocaleResolver {
    @Override
    public Locale resolveLocale(HttpServletRequest request) {
        String l = request.getParameter("l");
        //获取默认语言
        Locale locale = Locale.getDefault();
        if (!StringUtil.isEmpty(l)){
            String[] split = l.split("_");
            //获取国家，地址
            locale = new Locale(split[0],split[1]);
        }
        return locale;
    }

    @Override
    public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {

    }
}
